package com.atguigu.sparkcore.demo

import com.atguigu.sparkcore.util.MySparkContextUtil
import org.apache.spark.{SparkConf, SparkContext}
import org.apache.spark.rdd.RDD

/**
  * Rdd数据操作demo
  * author 剧情再美终是戏
  * mail 13286520398@163.com
  * date 2020/1/6 21:18 
  * version 1.0
  **/
object RddDemo {

  def main(args: Array[String]): Unit = {

    // 获取sparkContext
    val sc = MySparkContextUtil.get(args)

    // 创建rdd
    val list = Array(10, 20, 30, 40, 50, 10, 20)
    val rdd = sc.makeRDD(list, 2)

    // 转换rdd
    val result = rdd.coalesce(1)

    // 输出
    println(result.collect().mkString(","))

    // 关闭资源
    MySparkContextUtil.close(sc)
  }

}
